﻿using System;
using System.Windows.Forms;

namespace IceDog.WebServiceClient
{
    public partial class FormClientMain : Form
    {
        public FormClientMain()
        {
            InitializeComponent();
        }

        private void buttonTime_Click(object sender, EventArgs e)
        {
            var client = new TimeServiceReference.TimeServiceSoapClient();
            client.GetTimeNowCompleted += (sender2, e2) =>
            {
                if (e2.Error == null)
                {
                    textBoxResult.Text = e2.Result;
                }
                else
                {
                    MessageBox.Show(e2.Error.Message);
                }
            };
            client.GetTimeNowAsync();
        }

        private void buttonReverse_Click(object sender, EventArgs e)
        {
            var client = new StringServiceReference.StringServiceSoapClient();
            //接收数据
            client.ReverseStringCompleted += (sender2, e2) =>
            {
                if (e2.Error == null)
                {
                    textBoxResult.Text = e2.Result;
                }
                else
                {
                    MessageBox.Show(e2.Error.Message);
                }
            };
            //发送数据
            client.ReverseStringAsync(textBoxResult.Text);
        }

        private void buttonDayOfWeek_Click(object sender, EventArgs e)
        {
            var client = new TimeServiceReference.TimeServiceSoapClient();
            client.GetDayOfWeekNowCompleted += (sender2, e2) =>
            {
                if (e2.Error == null)
                {
                    textBoxResult.Text = e2.Result;
                }
                else
                {
                    MessageBox.Show(e2.Error.Message);
                }
            };
            client.GetDayOfWeekNowAsync();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            WeatherServiceReference.TemperatureType type;
            if (radioButton1.Checked)
            {
                type = WeatherServiceReference.TemperatureType.Celsius;
            }
            else
            {
                type = WeatherServiceReference.TemperatureType.Fahrenheit;
            }
            var req = new WeatherServiceReference.GetWeatherRequest()
            {
                City = comboBox1.Text,
                TemperatureType = type
            };
            var res = new WeatherServiceReference.GetWeatherResponse();
            res = new WeatherServiceReference.WeatherServiceSoapClient().GetWeather(req);
            textBox1.Text = res.Temperature.ToString();
            textBox2.Text = res.TemperatureCondition.ToString();
        }
    }
}
